# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=LibRaw

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.16.0
pkgrel=1
pkgdesc="Library for reading RAW files obtained from digital photo cameras (mingw-w64)"
arch=(any)
url="http://www.libraw.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-lcms2"
    "${MINGW_PACKAGE_PREFIX}-jasper")
options=('staticlibs' 'strip')
source=("http://www.libraw.org/data/${_realname}-${pkgver}.tar.gz"
    "http://www.libraw.org/data/${_realname}-demosaic-pack-GPL2-${pkgver}.tar.gz"
    "http://www.libraw.org/data/${_realname}-demosaic-pack-GPL3-${pkgver}.tar.gz"
    "LibRaw_wsock32.patch"
    "LibRaw_obsolete-macros.patch")
sha256sums=('71f43871ec2535345c5c9b748f07813e49915170f9510b721a2be6478426cf96'
            '749d49694ce729166ec7a1faf7580780687ef190c756931bb075455ee8ed6697'
            'f2e904f9baa7d173b5ade163c795f26e110255a758e31bd213086a5a61500b5c'
            '4bd077917fb8f37fa736e3a8bf32fabe3df3ff5438b684acbb5adff8a6c2a73b'
            '4a31c0ee066f43915beff6f7959b6b2cd246d390720df379bfc047d4cedb6a8f')

prepare() {
  mv $srcdir/${_realname}-demosaic-pack-GPL2-${pkgver} $srcdir/${_realname}-$pkgver/
  mv $srcdir/${_realname}-demosaic-pack-GPL3-${pkgver} $srcdir/${_realname}-$pkgver/
  cd "$srcdir/${_realname}-$pkgver"
  patch -Np1 -i "$srcdir/LibRaw_wsock32.patch"
  patch -Np1 -i "$srcdir/LibRaw_obsolete-macros.patch"
  
  autoreconf -ifv
}

build() {
  CPPFLAGS+=" -DLIBRAW_NODLL"
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
    mkdir -p "${srcdir}/build-${MINGW_CHOST}"
    cd "${srcdir}/build-${MINGW_CHOST}"
    "${srcdir}"/${_realname}-$pkgver/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --enable-jasper \
    --enable-lcms \
    --enable-demosaic-pack-gpl2 \
    --enable-demosaic-pack-gpl3

    make
}

package() {
    cd "${srcdir}/build-${MINGW_CHOST}"
    make DESTDIR="$pkgdir" install
}
